package com.qy139.auth.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qy139.auth.service.ITabUserService;
import com.qy139.entity.TabUser;
import com.qy139.util.Result;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuhaochen
 * @since 2021-12-01
 */
@RestController
@RequestMapping("/tab-user")
public class TabUserController {
    @Resource
    private ITabUserService userService;

    @PostMapping("/getByUserName")
    public TabUser getUserByName(String s){
        System.out.println("--------用户名是:"+s);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("name",s);
        TabUser one = userService.getOne(queryWrapper);
        return one;
    }

    @PostMapping("/findRolesById")
    public List<String> findRolesById(Integer id){
        List<String> rolesById = userService.findRolesById(id);
        return rolesById;
    }

    @GetMapping("/findAllUser")
    public Result showUser(Page<TabUser> page,String name){
        IPage page1=userService.selectAllUser(page, name);
        return new Result(page1);
    }

    @PostMapping("/addUser")
    public Result addUser(@RequestBody TabUser tabUser){
        return new Result(userService.addUser(tabUser));
    }

    @PutMapping("/updUser")
    public Result updUser(@RequestBody TabUser tabUser){
        return new Result(userService.updUser(tabUser));
    }

    @PostMapping("/deleteUser")
    public Result deleteUser(@RequestBody TabUser tabUser){
        return userService.deleteUser(tabUser);
    }
}

